----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/code/logs/table_A1_gravity_coef.log
  log type:  text
 opened on:  31 Oct 2022, 01:24:58

. *-------------------------------------------------------------------------------
. 
. local title "naics_sales_s1_base_woparent"

. clear all

. use "${data}/gravitycoef_`title'.dta", clear

. keep sector coef_* se_*

. 
. 
. gen sector_order="NA"

. 
. *Other goods
. *---------------------------------------
. replace sector_order="1.1" if sector=="AgrMining (A-B)"
variable sector_order was str2 now str3
(1 real change made)

. replace sector_order="1.2" if sector=="Electricity (D-E)"
(1 real change made)

. replace sector_order="1.2" if sector=="Construction (F)"
(1 real change made)

. 
. *Manufacturing
. *---------------------------------------
. replace sector_order="2.1" if sector=="Food (10-12)"
(1 real change made)

. replace sector_order="2.2" if sector=="TexWood (13-18)"
(1 real change made)

. replace sector_order="2.3" if sector=="ChePetPla (19-23)"
(1 real change made)

. replace sector_order="2.4" if sector=="Basic Metals (24-25)"
(1 real change made)

. replace sector_order="2.5" if sector=="ElecMach (26-28)"
(1 real change made)

. replace sector_order="2.6" if sector=="TranspOtherManuf (29-33)"
(1 real change made)

. 
. *Services
. *---------------------------------------
. replace sector_order="3.1" if sector=="Wholesale_Retail (G)"
(1 real change made)

. replace sector_order="3.2" if sector=="Transportation_Storage (H)"
(1 real change made)

. replace sector_order="3.3" if sector=="Information (J)"
(1 real change made)

. replace sector_order="3.4" if sector=="Financial_Insurance (K)"
(1 real change made)

. replace sector_order="3.5" if sector=="Support_Services (M-N)"
(1 real change made)

. replace sector_order="3.6" if sector=="Accomod_Recreat (I-R-S)"
(1 real change made)

. 
. *Other sectors
. *---------------------------------------
. replace sector_order="4.1" if sector=="Education (P)"
(1 real change made)

. replace sector_order="4.2" if sector=="Health (Q)"
(1 real change made)

. replace sector_order="4.3" if sector=="Real_Estate (L)"
(1 real change made)

. 
. drop if sector=="Public_Administration (O)"
(1 observation deleted)

. sort sector_order

. order sector_order sector

. 
. format %9.3fc coef_* se_*

. 
. export delimited using "${rappendix}/table_A1_gravity_coef.csv", datafmt replace
(note: file F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/results/appendix/table_A1_gravity_coef.csv not f
> ound)
file F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/results/appendix/table_A1_gravity_coef.csv saved

. 
end of do-file

. do "C:\Users\VANESS~1\AppData\Local\Temp\STD2d9c_000000.tmp"

. *-------------------------------------------------------------------------------
. global typeden=1

. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main"

. global cappendix "${root}/code/appendix"

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main"

. global rappendix  "${root}/results/appendix"

. 
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. *global maindirectory "F:/Dropbox (UBC-Umich)"
. *global maindirectory "C:\Users\cheoy\Dropbox (UBC-Umich)"
. *global tfp "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical" 
. *global tfp_bef "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data" 
. *global orbis_historical "${maindirectory}/Master_Dataset/Orbis_master/Javier_Florian/orbis_data/final_data"
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. 
. *global inputs "${tfp}/data/inputs"
. *global code "${tfp}/code"
. *global output "${tfp}/data/output"
. *global results "${tfp}/results"
. 
. 
. 
. 
. 
. 
. 
. 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. global lf "LF"

. 
. *Log
. *cap log close
. *log using "${clogs}/figure_03_phi_pop.log",replace
. *-------------------------------------------------------------------------------
. 
. 
. 
. *-----------------------------------------------------------------
. clear all

. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. local grvar0 "gdp_pw_ppp" 

. local grvar1 "" 

. local rr ""

. local var3 "A"

. local yy "2016"

. local yy_ref=`yy'       

. replace year=`yy_ref'
(0 real changes made)

. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(2,985 observations deleted)

. drop _merge

. 
. foreach var in D_A  {
  2. gen `var'_phi=(-1)*`var'*(0.2)
  3. *---------------------------------------
. gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
  4. }

. 
. local LHS ln_`grvar0'

. local RHS2 ln_pop

. local RHS1 D_`var3'_phi

. 
. reg `LHS1' `RHS' `RHS2'

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(0, 26)        =      0.00
       Model |           0         0           .   Prob > F        =         .
    Residual |  44.8459541        26  1.72484439   R-squared       =    0.0000
-------------+----------------------------------   Adj R-squared   =    0.0000
       Total |  44.8459541        26  1.72484439   Root MSE        =    1.3133

------------------------------------------------------------------------------
      ln_pop |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   -1.56051   .2527511    -6.17   0.000    -2.080048   -1.040973
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-04.2fc round(b[1,1],0.0001)

. global se1: display %-04.2fc round(sqrt(V[1,1]),0.0001)

. 
. 
. 
end of do-file

. *-----------------------------------------------------------------

. 
. clear all

. 
. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. 
. 
. local grvar0 "gdp_pw_ppp" 

. 
. local grvar1 ""

. 
. local var3 "A"

. 
. local yy "2016"

. 
. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. 
. drop if _merge==2
(2,985 observations deleted)

. 
. drop _merge

. 
. 
. 
. foreach var in D_A  {
  2. 
. gen `var'_phi=(-1)*`var'*(0.2)
  3. 
. *---------------------------------------
. 
. gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
  4. 
. }

. 
. 
. 
. local LHS ln_`grvar0'

. 
. local RHS2 ln_pop

. 
. local RHS1 D_`var3'_phi

. 
. 
. 
. reg `LHS1' `RHS1' `RHS2'

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(2, 24)        =         .
       Model |  .684354518         2  .342177259   Prob > F        =         .
    Residual |           0        24           0   R-squared       =    1.0000
-------------+----------------------------------   Adj R-squared   =    1.0000
       Total |  .684354518        26  .026321328   Root MSE        =         0

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     D_A_phi |          1          .        .       .            .           .
      ln_pop |   1.28e-16          .        .       .            .           .
       _cons |          0  (omitted)
------------------------------------------------------------------------------

. reg `LHS' `RHS1' `RHS2'

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(2, 24)        =     19.02
       Model |  1.19704191         2  .598520953   Prob > F        =    0.0000
    Residual |  .755156001        24  .031464833   R-squared       =    0.6132
-------------+----------------------------------   Adj R-squared   =    0.5809
       Total |  1.95219791        26  .075084535   Root MSE        =    .17738

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     D_A_phi |   3.316076    .596757     5.56   0.000      2.08443    4.547722
      ln_pop |  -.3113793   .0737185    -4.22   0.000    -.4635268   -.1592318
       _cons |  -.1515243   .0555527    -2.73   0.012    -.2661794   -.0368692
------------------------------------------------------------------------------

. reg `LHS' `RHS1' `RHS2', noco

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(2, 25)        =     52.33
       Model |  4.14151211         2  2.07075606   Prob > F        =    0.0000
    Residual |  .989244309        25  .039569772   R-squared       =    0.8072
-------------+----------------------------------   Adj R-squared   =    0.7918
       Total |  5.13075642        27  .190028016   Root MSE        =    .19892

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     D_A_phi |    3.74285    .645804     5.80   0.000     2.412792    5.072908
      ln_pop |  -.3068209   .0826483    -3.71   0.001    -.4770383   -.1366036
------------------------------------------------------------------------------

. *-----------------------------------------------------------------

. 
. clear all

. 
. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. 
. 
. local grvar0 "gdp_pw_ppp" 

. 
. local grvar1 ""

. 
. local var3 "A"

. 
. local yy "2016"

. 
. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. 
. drop if _merge==2
(2,985 observations deleted)

. 
. drop _merge

. 
. 
. 
. foreach var in D_A  {
  2. 
. gen `var'_phi=(-1)*`var'*(0.2)
  3. 
. *---------------------------------------
. 
. gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
  4. 
. }

. 
. 
. 
. local LHS1 D_`var3'_phi

. 
. local RHS ln_`grvar0'

. 
. local RHS2 ln_pop

. 
. 
. 
. 
. 
. reg `LHS1' `RHS2', nocon

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =    470.38
       Model |  1.71648939         1  1.71648939   Prob > F        =    0.0000
    Residual |  .094877256        26  .003649125   R-squared       =    0.9476
-------------+----------------------------------   Adj R-squared   =    0.9456
       Total |  1.81136665        27  .067087654   Root MSE        =    .06041

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1245806   .0057441    21.69   0.000     .1127734    .1363879
------------------------------------------------------------------------------

. 
. mat b = e(b)

. 
. mat V = e(V)

. 
. global c_first: display %-03.2fc round(b[1,1],0.0001)

. 
. global se_first: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. 
. predict lhs, res

. 
. 
. 
. reg `RHS' `RHS2', nocon 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =     31.54
       Model |  2.81238372         1  2.81238372   Prob > F        =    0.0000
    Residual |   2.3183727        26  .089168181   R-squared       =    0.5481
-------------+----------------------------------   Adj R-squared   =    0.5308
       Total |  5.13075642        27  .190028016   Root MSE        =    .29861

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1594657   .0283945     5.62   0.000     .1010999    .2178315
------------------------------------------------------------------------------

. 
. mat b = e(b)

. 
. mat V = e(V)

. 
. global c_second: display %-03.2fc round(b[1,1],0.0001)

. 
. global se_second: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. 
. predict rhs, res

. 
. 
. 
. reg lhs rhs

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 25)        =     32.84
       Model |  .052369611         1  .052369611   Prob > F        =    0.0000
    Residual |  .039862852        25  .001594514   R-squared       =    0.5678
-------------+----------------------------------   Adj R-squared   =    0.5505
       Total |  .092232463        26  .003547402   Root MSE        =    .03993

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         rhs |   .1587333   .0276976     5.73   0.000     .1016889    .2157776
       _cons |   .0050653   .0081162     0.62   0.538    -.0116503    .0217809
------------------------------------------------------------------------------

. do "C:\Users\VANESS~1\AppData\Local\Temp\STD2d9c_000000.tmp"

. clear all

. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. local grvar0 "gdp_pw_ppp" 

. local grvar1 "" 

. local var3 "A"

. local yy "2016"

. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(2,985 observations deleted)

. drop _merge

. 
. foreach var in D_A  {
  2. gen `var'_phi=(-1)*`var'*(0.2)
  3. *---------------------------------------
. gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
  4. }

. 
. local LHS1 D_`var3'_phi

. local RHS ln_`grvar0'

. local RHS2 ln_pop

. 
. 
. reg `LHS1' `RHS2', nocon

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =    470.38
       Model |  1.71648939         1  1.71648939   Prob > F        =    0.0000
    Residual |  .094877256        26  .003649125   R-squared       =    0.9476
-------------+----------------------------------   Adj R-squared   =    0.9456
       Total |  1.81136665        27  .067087654   Root MSE        =    .06041

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1245806   .0057441    21.69   0.000     .1127734    .1363879
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_first: display %-03.2fc round(b[1,1],0.0001)

. global se_first: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict lhs, res

. 
. reg `RHS' `RHS2', nocon 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =     31.54
       Model |  2.81238372         1  2.81238372   Prob > F        =    0.0000
    Residual |   2.3183727        26  .089168181   R-squared       =    0.5481
-------------+----------------------------------   Adj R-squared   =    0.5308
       Total |  5.13075642        27  .190028016   Root MSE        =    .29861

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1594657   .0283945     5.62   0.000     .1010999    .2178315
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_second: display %-03.2fc round(b[1,1],0.0001)

. global se_second: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict rhs, res

. 
. reg lhs rhs 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 25)        =     32.84
       Model |  .052369611         1  .052369611   Prob > F        =    0.0000
    Residual |  .039862852        25  .001594514   R-squared       =    0.5678
-------------+----------------------------------   Adj R-squared   =    0.5505
       Total |  .092232463        26  .003547402   Root MSE        =    .03993

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         rhs |   .1587333   .0276976     5.73   0.000     .1016889    .2157776
       _cons |   .0050653   .0081162     0.62   0.538    -.0116503    .0217809
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-03.2fc round(b[1,1],0.01)

. global se1: display %-03.2fc round(sqrt(V[1,1]),0.01)

. display "$c1"
0.16

. 
. 
. global opt1 msymbol(circle_hollow) mlabel(isocode) mlabcolor(red)  msize(small) mlabsize(small)

. global opt2 msymbol(square_hollow) mlabel(isocode) mlabcolor(blue) msize(small) mlabsize(small)

. two (scatter lhs rhs, sort $opt1  mcolor(red)) (lfit lhs rhs, lcolor(red)) (line lhs lhs, lcolor(none)) ,  ylabel(-0.4(0.2)0.2, format(%5.1f) labsize(medlarge)) xlabel(-1(0.2)0
> .4, format(%5.1f) labsize(medlarge)) ///
>         title("", size(small)) ytitle("`ytitle'", size(medlarge)) xtitle("`xtitle'", size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
>         legend(order(2 "`ytitle': $c1 ($se1)") rows(1) size(medlarge) bplace(se) ring(0) region(lwidth(none))) 

. 
end of do-file

. *-----------------------------------------------------------------

. 
. clear all

. 
. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. 
. 
. local grvar0 "gdp_pw_ppp" 

. 
. local grvar1 ""

. 
. local var3 "A"

. 
. local yy "2016"

. 
. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. 
. drop if _merge==2
(2,985 observations deleted)

. 
. drop _merge

. 
. 
. 
. foreach var in D_A  {
  2. 
. gen `var'_phi=(-1)*`var'*(0.2)
  3. 
. *---------------------------------------
. 
. gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
  4. 
. }

. 
. 
. 
. local LHS1 D_`var3'_phi

. 
. local RHS ln_`grvar0'

. 
. local RHS2 ln_pop

. 
. 
. 
. reg `LHS1' `RHS' `RHS2'

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(2, 24)        =    200.53
       Model |  .645714201         2  .322857101   Prob > F        =    0.0000
    Residual |  .038640316        24  .001610013   R-squared       =    0.9435
-------------+----------------------------------   Adj R-squared   =    0.9388
       Total |  .684354518        26  .026321328   Root MSE        =    .04012

-------------------------------------------------------------------------------
      D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
ln_gdp_pw_ppp |   .1696791   .0305353     5.56   0.000     .1066575    .2327008
       ln_pop |    .103251   .0063709    16.21   0.000      .090102    .1163999
        _cons |   .0150362   .0140514     1.07   0.295    -.0139645    .0440368
-------------------------------------------------------------------------------

. 
. mat b = e(b)

. 
. mat V = e(V)

. 
. global c1: display %-04.2fc round(b[1,1],0.0001)

. 
. global se1: display %-04.2fc round(sqrt(V[1,1]),0.0001)

. do "C:\Users\VANESS~1\AppData\Local\Temp\STD2d9c_000000.tmp"

. global typeden=1

. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main"

. global cappendix "${root}/code/appendix"

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main"

. global rappendix  "${root}/results/appendix"

. 
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. *global maindirectory "F:/Dropbox (UBC-Umich)"
. *global maindirectory "C:\Users\cheoy\Dropbox (UBC-Umich)"
. *global tfp "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical" 
. *global tfp_bef "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data" 
. *global orbis_historical "${maindirectory}/Master_Dataset/Orbis_master/Javier_Florian/orbis_data/final_data"
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. 
. *global inputs "${tfp}/data/inputs"
. *global code "${tfp}/code"
. *global output "${tfp}/data/output"
. *global results "${tfp}/results"
. 
. 
. 
. 
. 
. 
. 
. 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. global lf "LF"

. 
. *Log
. *cap log close
. *log using "${clogs}/figure_03_phi_pop.log",replace
. *-------------------------------------------------------------------------------
. 
. 
. 
. *-----------------------------------------------------------------
. clear all

. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. local grvar0 "gdp_pw_ppp" 

. local grvar1 "" 

. local var3 "A"

. local yy "2016"

. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(2,985 observations deleted)

. drop _merge

. 
. foreach var in D_A  {
  2. gen `var'_phi=(-1)*`var'*(0.2)
  3. *---------------------------------------
. gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
  4. }

. 
. local LHS1 D_`var3'_phi

. local RHS ln_`grvar0'

. local RHS2 ln_pop

. 
. reg `LHS1' `RHS2', nocon

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =    470.38
       Model |  1.71648939         1  1.71648939   Prob > F        =    0.0000
    Residual |  .094877256        26  .003649125   R-squared       =    0.9476
-------------+----------------------------------   Adj R-squared   =    0.9456
       Total |  1.81136665        27  .067087654   Root MSE        =    .06041

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1245806   .0057441    21.69   0.000     .1127734    .1363879
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_first: display %-03.2fc round(b[1,1],0.0001)

. global se_first: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict lhs, res

. 
. reg `RHS' `RHS2', nocon 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =     31.54
       Model |  2.81238372         1  2.81238372   Prob > F        =    0.0000
    Residual |   2.3183727        26  .089168181   R-squared       =    0.5481
-------------+----------------------------------   Adj R-squared   =    0.5308
       Total |  5.13075642        27  .190028016   Root MSE        =    .29861

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1594657   .0283945     5.62   0.000     .1010999    .2178315
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_second: display %-03.2fc round(b[1,1],0.0001)

. global se_second: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict rhs, res

. 
. reg lhs rhs 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 25)        =     32.84
       Model |  .052369611         1  .052369611   Prob > F        =    0.0000
    Residual |  .039862852        25  .001594514   R-squared       =    0.5678
-------------+----------------------------------   Adj R-squared   =    0.5505
       Total |  .092232463        26  .003547402   Root MSE        =    .03993

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         rhs |   .1587333   .0276976     5.73   0.000     .1016889    .2157776
       _cons |   .0050653   .0081162     0.62   0.538    -.0116503    .0217809
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-03.2fc round(b[1,1],0.01)

. global se1: display %-03.2fc round(sqrt(V[1,1]),0.01)

. display "$c1"
0.16

. 
. 
. global opt1 msymbol(circle_hollow) mlabel(isocode) mlabcolor(red)  msize(small) mlabsize(small)

. global opt2 msymbol(square_hollow) mlabel(isocode) mlabcolor(blue) msize(small) mlabsize(small)

. two (scatter lhs rhs, sort $opt1  mcolor(red)) (lfit lhs rhs, lcolor(red)) (line lhs lhs, lcolor(none)) ,  ylabel(-0.4(0.2)0.2, format(%5.1f) labsize(medlarge)) xlabel(-1(0.2)0
> .4, format(%5.1f) labsize(medlarge)) ///
>         title("", size(small)) ytitle("`ytitle'", size(medlarge)) xtitle("`xtitle'", size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
>         legend(order(2 "`ytitle': $c1 ($se1)") rows(1) size(medlarge) bplace(se) ring(0) region(lwidth(none))) 

. 
end of do-file

. do "C:\Users\VANESS~1\AppData\Local\Temp\STD2d9c_000000.tmp"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: figure_03_phi_pop.do
> Date: October 2022
> 
> Description: Reproduces Figure 3: Development accounting: firm-embedded productivity residualized by population.
> 
> *****************************************************************************************/
. 
. *-------------------------------------------------------------------------------
. global typeden=1

. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main"

. global cappendix "${root}/code/appendix"

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main"

. global rappendix  "${root}/results/appendix"

. 
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. *global maindirectory "F:/Dropbox (UBC-Umich)"
. *global maindirectory "C:\Users\cheoy\Dropbox (UBC-Umich)"
. *global tfp "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical" 
. *global tfp_bef "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data" 
. *global orbis_historical "${maindirectory}/Master_Dataset/Orbis_master/Javier_Florian/orbis_data/final_data"
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. 
. *global inputs "${tfp}/data/inputs"
. *global code "${tfp}/code"
. *global output "${tfp}/data/output"
. *global results "${tfp}/results"
. 
. 
. 
. 
. 
. 
. 
. 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. global lf "LF"

. 
. *Log
. *cap log close
. *log using "${clogs}/figure_03_phi_pop.log",replace
. *-------------------------------------------------------------------------------
. 
. 
. 
. *-----------------------------------------------------------------
. clear all

. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. local grvar0 "gdp_pw_ppp" 

. local grvar1 "" 

. local var3 "A"

. local yy "2016"

. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(2,985 observations deleted)

. drop _merge

. 
. foreach var in D_A  {
  2. gen `var'_phi=(-1)*`var'*(0.2)
  3. *---------------------------------------
. gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
  4. }

. 
. local LHS1 D_`var3'_phi

. local RHS ln_`grvar0'

. local RHS2 ln_pop

. 
. reg `LHS1' `RHS2', nocon

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =    470.38
       Model |  1.71648939         1  1.71648939   Prob > F        =    0.0000
    Residual |  .094877256        26  .003649125   R-squared       =    0.9476
-------------+----------------------------------   Adj R-squared   =    0.9456
       Total |  1.81136665        27  .067087654   Root MSE        =    .06041

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1245806   .0057441    21.69   0.000     .1127734    .1363879
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_first: display %-03.2fc round(b[1,1],0.0001)

. global se_first: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict lhs, res

. 
. reg `RHS' `RHS2', nocon 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =     31.54
       Model |  2.81238372         1  2.81238372   Prob > F        =    0.0000
    Residual |   2.3183727        26  .089168181   R-squared       =    0.5481
-------------+----------------------------------   Adj R-squared   =    0.5308
       Total |  5.13075642        27  .190028016   Root MSE        =    .29861

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1594657   .0283945     5.62   0.000     .1010999    .2178315
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_second: display %-03.2fc round(b[1,1],0.0001)

. global se_second: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict rhs, res

. 
. reg lhs rhs 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 25)        =     32.84
       Model |  .052369611         1  .052369611   Prob > F        =    0.0000
    Residual |  .039862852        25  .001594514   R-squared       =    0.5678
-------------+----------------------------------   Adj R-squared   =    0.5505
       Total |  .092232463        26  .003547402   Root MSE        =    .03993

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         rhs |   .1587333   .0276976     5.73   0.000     .1016889    .2157776
       _cons |   .0050653   .0081162     0.62   0.538    -.0116503    .0217809
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-03.2fc round(b[1,1],0.01)

. global se1: display %-03.2fc round(sqrt(V[1,1]),0.01)

. display "$c1"
0.16

. 
. 
. local ytitle "{&Delta}`=ustrunescape("\u03D5\u0303")'{sub:n}, {&Delta}`=ustrunescape("\u007A\u0303")'{sub:n}"

. local xtitle "{&Delta}y{sub:n}"

. 
. global opt1 msymbol(circle_hollow) mlabel(isocode) mlabcolor(red)  msize(small) mlabsize(small)

. global opt2 msymbol(square_hollow) mlabel(isocode) mlabcolor(blue) msize(small) mlabsize(small)

. two (scatter lhs rhs, sort $opt1  mcolor(red)) (lfit lhs rhs, lcolor(red)) (line lhs lhs, lcolor(none)) ,  ylabel(-0.4(0.2)0.2, format(%5.1f) labsize(medlarge)) xlabel(-1(0.2)0
> .4, format(%5.1f) labsize(medlarge)) ///
>         title("", size(small)) ytitle("`ytitle'", size(medlarge)) xtitle("`xtitle'", size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
>         legend(order(2 "`ytitle': $c1 ($se1)") rows(1) size(medlarge) bplace(se) ring(0) region(lwidth(none))) 

. 
end of do-file

. do "C:\Users\VANESS~1\AppData\Local\Temp\STD2d9c_000000.tmp"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: figure_03_phi_pop.do
> Date: October 2022
> 
> Description: Reproduces Figure 3: Development accounting: firm-embedded productivity residualized by population.
> 
> *****************************************************************************************/
. 
. *-------------------------------------------------------------------------------
. global typeden=1

. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main"

. global cappendix "${root}/code/appendix"

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main"

. global rappendix  "${root}/results/appendix"

. 
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. *global maindirectory "F:/Dropbox (UBC-Umich)"
. *global maindirectory "C:\Users\cheoy\Dropbox (UBC-Umich)"
. *global tfp "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical" 
. *global tfp_bef "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data" 
. *global orbis_historical "${maindirectory}/Master_Dataset/Orbis_master/Javier_Florian/orbis_data/final_data"
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. 
. *global inputs "${tfp}/data/inputs"
. *global code "${tfp}/code"
. *global output "${tfp}/data/output"
. *global results "${tfp}/results"
. 
. 
. 
. 
. 
. 
. 
. 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. global lf "LF"

. 
. *Log
. *cap log close
. *log using "${clogs}/figure_03_phi_pop.log",replace
. *-------------------------------------------------------------------------------
. 
. 
. 
. *-----------------------------------------------------------------
. clear all

. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. local grvar0 "gdp_pw_ppp" 

. local grvar1 "" 

. local var3 "A"

. local yy "2016"

. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(2,985 observations deleted)

. drop _merge

. 
. foreach var in D_A  {
  2. gen `var'_phi=(-1)*`var'*(0.2)
  3. *---------------------------------------
. gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
  4. }

. 
. local LHS1 D_`var3'_phi

. local RHS ln_`grvar0'

. local RHS2 ln_pop

. 
. reg `LHS1' `RHS2', nocon

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =    470.38
       Model |  1.71648939         1  1.71648939   Prob > F        =    0.0000
    Residual |  .094877256        26  .003649125   R-squared       =    0.9476
-------------+----------------------------------   Adj R-squared   =    0.9456
       Total |  1.81136665        27  .067087654   Root MSE        =    .06041

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1245806   .0057441    21.69   0.000     .1127734    .1363879
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_first: display %-03.2fc round(b[1,1],0.0001)

. global se_first: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict lhs, res

. 
. reg `RHS' `RHS2', nocon 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =     31.54
       Model |  2.81238372         1  2.81238372   Prob > F        =    0.0000
    Residual |   2.3183727        26  .089168181   R-squared       =    0.5481
-------------+----------------------------------   Adj R-squared   =    0.5308
       Total |  5.13075642        27  .190028016   Root MSE        =    .29861

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1594657   .0283945     5.62   0.000     .1010999    .2178315
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_second: display %-03.2fc round(b[1,1],0.0001)

. global se_second: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict rhs, res

. 
. reg lhs rhs 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 25)        =     32.84
       Model |  .052369611         1  .052369611   Prob > F        =    0.0000
    Residual |  .039862852        25  .001594514   R-squared       =    0.5678
-------------+----------------------------------   Adj R-squared   =    0.5505
       Total |  .092232463        26  .003547402   Root MSE        =    .03993

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         rhs |   .1587333   .0276976     5.73   0.000     .1016889    .2157776
       _cons |   .0050653   .0081162     0.62   0.538    -.0116503    .0217809
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-03.2fc round(b[1,1],0.01)

. global se1: display %-03.2fc round(sqrt(V[1,1]),0.01)

. display "$c1"
0.16

. 
. 
. local ytitle "{&Delta}`=ustrunescape("\u03D5\u0303")'{sub:n}"

. local xtitle "{&Delta}y{sub:n}"

. 
. global opt1 msymbol(circle_hollow) mlabel(isocode) mlabcolor(red)  msize(small) mlabsize(small)

. global opt2 msymbol(square_hollow) mlabel(isocode) mlabcolor(blue) msize(small) mlabsize(small)

. two (scatter lhs rhs, sort $opt1  mcolor(red)) (lfit lhs rhs, lcolor(red)) (line lhs lhs, lcolor(none)) ,  ylabel(-0.4(0.2)0.2, format(%5.1f) labsize(medlarge)) xlabel(-1(0.2)0
> .4, format(%5.1f) labsize(medlarge)) ///
>         title("", size(small)) ytitle("`ytitle'", size(medlarge)) xtitle("`xtitle'", size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
>         legend(order(2 "`ytitle': $c1 ($se1)") rows(1) size(medlarge) bplace(se) ring(0) region(lwidth(none))) 

. 
end of do-file

. do "C:\Users\VANESS~1\AppData\Local\Temp\STD2d9c_000000.tmp"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: figure_03_phi_pop.do
> Date: October 2022
> 
> Description: Reproduces Figure 3: Development accounting: firm-embedded productivity residualized by population.
> 
> *****************************************************************************************/
. 
. *-------------------------------------------------------------------------------
. global typeden=1

. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main"

. global cappendix "${root}/code/appendix"

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main"

. global rappendix  "${root}/results/appendix"

. 
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. *global maindirectory "F:/Dropbox (UBC-Umich)"
. *global maindirectory "C:\Users\cheoy\Dropbox (UBC-Umich)"
. *global tfp "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical" 
. *global tfp_bef "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data" 
. *global orbis_historical "${maindirectory}/Master_Dataset/Orbis_master/Javier_Florian/orbis_data/final_data"
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. 
. *global inputs "${tfp}/data/inputs"
. *global code "${tfp}/code"
. *global output "${tfp}/data/output"
. *global results "${tfp}/results"
. 
. 
. 
. 
. 
. 
. 
. 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. global lf "LF"

. 
. *Log
. *cap log close
. *log using "${clogs}/figure_03_phi_pop.log",replace
. *-------------------------------------------------------------------------------
. 
. 
. 
. *-----------------------------------------------------------------
. clear all

. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. local grvar0 "gdp_pw_ppp" 

. local grvar1 "" 

. local var3 "A"

. local yy "2016"

. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(2,985 observations deleted)

. drop _merge

. 
. foreach var in D_A  {
  2. gen `var'_phi=(-1)*`var'*(0.2)
  3. *---------------------------------------
. gen b_`var'_phi_`grvar0'=ln_`grvar0' - `var'_phi
  4. }

. 
. local LHS1 D_`var3'_phi

. local RHS ln_`grvar0'

. local RHS2 ln_pop

. 
. reg `LHS1' `RHS2', nocon

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =    470.38
       Model |  1.71648939         1  1.71648939   Prob > F        =    0.0000
    Residual |  .094877256        26  .003649125   R-squared       =    0.9476
-------------+----------------------------------   Adj R-squared   =    0.9456
       Total |  1.81136665        27  .067087654   Root MSE        =    .06041

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1245806   .0057441    21.69   0.000     .1127734    .1363879
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_first: display %-03.2fc round(b[1,1],0.0001)

. global se_first: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict lhs, res

. 
. reg `RHS' `RHS2', nocon 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =     31.54
       Model |  2.81238372         1  2.81238372   Prob > F        =    0.0000
    Residual |   2.3183727        26  .089168181   R-squared       =    0.5481
-------------+----------------------------------   Adj R-squared   =    0.5308
       Total |  5.13075642        27  .190028016   Root MSE        =    .29861

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1594657   .0283945     5.62   0.000     .1010999    .2178315
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_second: display %-03.2fc round(b[1,1],0.0001)

. global se_second: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict rhs, res

. 
. reg lhs rhs 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 25)        =     32.84
       Model |  .052369611         1  .052369611   Prob > F        =    0.0000
    Residual |  .039862852        25  .001594514   R-squared       =    0.5678
-------------+----------------------------------   Adj R-squared   =    0.5505
       Total |  .092232463        26  .003547402   Root MSE        =    .03993

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         rhs |   .1587333   .0276976     5.73   0.000     .1016889    .2157776
       _cons |   .0050653   .0081162     0.62   0.538    -.0116503    .0217809
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-03.2fc round(b[1,1],0.01)

. global se1: display %-03.2fc round(sqrt(V[1,1]),0.01)

. display "$c1"
0.16

. 
. 
. local ytitle "{&Delta}`=ustrunescape("\u03D5\u0305")'{sub:n}"

. local xtitle "{&Delta}y{sub:n}"

. 
. global opt1 msymbol(circle_hollow) mlabel(isocode) mlabcolor(red)  msize(small) mlabsize(small)

. global opt2 msymbol(square_hollow) mlabel(isocode) mlabcolor(blue) msize(small) mlabsize(small)

. two (scatter lhs rhs, sort $opt1  mcolor(red)) (lfit lhs rhs, lcolor(red)) (line lhs lhs, lcolor(none)) ,  ylabel(-0.4(0.2)0.2, format(%5.1f) labsize(medlarge)) xlabel(-1(0.2)0
> .4, format(%5.1f) labsize(medlarge)) ///
>         title("", size(small)) ytitle("`ytitle'", size(medlarge)) xtitle("`xtitle'", size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
>         legend(order(2 "`ytitle': $c1 ($se1)") rows(1) size(medlarge) bplace(se) ring(0) region(lwidth(none))) 

. 
end of do-file

. do "C:\Users\VANESS~1\AppData\Local\Temp\STD2d9c_000000.tmp"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: figure_03_phi_pop.do
> Date: October 2022
> 
> Description: Reproduces Figure 3: Development accounting: firm-embedded productivity residualized by population.
> 
> *****************************************************************************************/
. 
. *-------------------------------------------------------------------------------
. global typeden=1

. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main"

. global cappendix "${root}/code/appendix"

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main"

. global rappendix  "${root}/results/appendix"

. 
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. *global maindirectory "F:/Dropbox (UBC-Umich)"
. *global maindirectory "C:\Users\cheoy\Dropbox (UBC-Umich)"
. *global tfp "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical" 
. *global tfp_bef "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data" 
. *global orbis_historical "${maindirectory}/Master_Dataset/Orbis_master/Javier_Florian/orbis_data/final_data"
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. 
. *global inputs "${tfp}/data/inputs"
. *global code "${tfp}/code"
. *global output "${tfp}/data/output"
. *global results "${tfp}/results"
. 
. 
. 
. 
. 
. 
. 
. 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. global lf "LF"

. 
. *Log
. *cap log close
. *log using "${clogs}/figure_03_phi_pop.log",replace
. *-------------------------------------------------------------------------------
. 
. 
. 
. *-----------------------------------------------------------------
. clear all

. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. local grvar0 "gdp_pw_ppp" 

. local grvar1 "" 

. local var3 "A"

. local yy "2016"

. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(2,985 observations deleted)

. drop _merge

. 
. foreach var in D_A  {
  2. gen `var'_phi=(-1)*`var'*(0.2)
  3. }

. 
. local LHS1 D_`var3'_phi

. local LHS2 ln_`grvar0'

. local RHS ln_pop

. 
. reg `LHS1' `RHS', nocon

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =    470.38
       Model |  1.71648939         1  1.71648939   Prob > F        =    0.0000
    Residual |  .094877256        26  .003649125   R-squared       =    0.9476
-------------+----------------------------------   Adj R-squared   =    0.9456
       Total |  1.81136665        27  .067087654   Root MSE        =    .06041

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1245806   .0057441    21.69   0.000     .1127734    .1363879
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_first: display %-03.2fc round(b[1,1],0.0001)

. global se_first: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict lhs, res

. 
. reg `LHS2' `RHS', nocon 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =     31.54
       Model |  2.81238372         1  2.81238372   Prob > F        =    0.0000
    Residual |   2.3183727        26  .089168181   R-squared       =    0.5481
-------------+----------------------------------   Adj R-squared   =    0.5308
       Total |  5.13075642        27  .190028016   Root MSE        =    .29861

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1594657   .0283945     5.62   0.000     .1010999    .2178315
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_second: display %-03.2fc round(b[1,1],0.0001)

. global se_second: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict rhs, res

. 
. reg lhs rhs 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 25)        =     32.84
       Model |  .052369611         1  .052369611   Prob > F        =    0.0000
    Residual |  .039862852        25  .001594514   R-squared       =    0.5678
-------------+----------------------------------   Adj R-squared   =    0.5505
       Total |  .092232463        26  .003547402   Root MSE        =    .03993

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         rhs |   .1587333   .0276976     5.73   0.000     .1016889    .2157776
       _cons |   .0050653   .0081162     0.62   0.538    -.0116503    .0217809
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-03.2fc round(b[1,1],0.01)

. global se1: display %-03.2fc round(sqrt(V[1,1]),0.01)

. display "$c1"
0.16

. 
. reg `LHS1' `LHS2' `RHS'

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(2, 24)        =    200.53
       Model |  .645714201         2  .322857101   Prob > F        =    0.0000
    Residual |  .038640316        24  .001610013   R-squared       =    0.9435
-------------+----------------------------------   Adj R-squared   =    0.9388
       Total |  .684354518        26  .026321328   Root MSE        =    .04012

-------------------------------------------------------------------------------
      D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
ln_gdp_pw_ppp |   .1696791   .0305353     5.56   0.000     .1066575    .2327008
       ln_pop |    .103251   .0063709    16.21   0.000      .090102    .1163999
        _cons |   .0150362   .0140514     1.07   0.295    -.0139645    .0440368
-------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-04.2fc round(b[1,1],0.0001)

. global se1: display %-04.2fc round(sqrt(V[1,1]),0.0001)

. 
end of do-file

. do "C:\Users\VANESS~1\AppData\Local\Temp\STD2d9c_000000.tmp"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: figure_03_phi_pop.do
> Date: October 2022
> 
> Description: Reproduces Figure 3: Development accounting: firm-embedded productivity residualized by population.
> 
> *****************************************************************************************/
. 
. *-------------------------------------------------------------------------------
. global typeden=1

. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main"

. global cappendix "${root}/code/appendix"

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main"

. global rappendix  "${root}/results/appendix"

. 
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. *global maindirectory "F:/Dropbox (UBC-Umich)"
. *global maindirectory "C:\Users\cheoy\Dropbox (UBC-Umich)"
. *global tfp "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical" 
. *global tfp_bef "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data" 
. *global orbis_historical "${maindirectory}/Master_Dataset/Orbis_master/Javier_Florian/orbis_data/final_data"
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. 
. *global inputs "${tfp}/data/inputs"
. *global code "${tfp}/code"
. *global output "${tfp}/data/output"
. *global results "${tfp}/results"
. 
. 
. 
. 
. 
. 
. 
. 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. global lf "LF"

. 
. *Log
. *cap log close
. *log using "${clogs}/figure_03_phi_pop.log",replace
. *-------------------------------------------------------------------------------
. 
. 
. 
. *-----------------------------------------------------------------
. clear all

. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. local grvar0 "gdp_pw_ppp" 

. local grvar1 "" 

. local var3 "A"

. local yy "2016"

. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(2,985 observations deleted)

. drop _merge

. 
. foreach var in D_A  {
  2. gen `var'_phi=(-1)*`var'*(0.2)
  3. }

. 
. local LHS1 D_`var3'_phi

. local LHS2 ln_`grvar0'

. local RHS ln_pop

. 
. reg `LHS1' `RHS', nocon

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =    470.38
       Model |  1.71648939         1  1.71648939   Prob > F        =    0.0000
    Residual |  .094877256        26  .003649125   R-squared       =    0.9476
-------------+----------------------------------   Adj R-squared   =    0.9456
       Total |  1.81136665        27  .067087654   Root MSE        =    .06041

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1245806   .0057441    21.69   0.000     .1127734    .1363879
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_first: display %-03.2fc round(b[1,1],0.0001)

. global se_first: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict lhs, res

. 
. reg `LHS2' `RHS', nocon 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =     31.54
       Model |  2.81238372         1  2.81238372   Prob > F        =    0.0000
    Residual |   2.3183727        26  .089168181   R-squared       =    0.5481
-------------+----------------------------------   Adj R-squared   =    0.5308
       Total |  5.13075642        27  .190028016   Root MSE        =    .29861

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1594657   .0283945     5.62   0.000     .1010999    .2178315
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_second: display %-03.2fc round(b[1,1],0.0001)

. global se_second: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict rhs, res

. 
. reg lhs rhs 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 25)        =     32.84
       Model |  .052369611         1  .052369611   Prob > F        =    0.0000
    Residual |  .039862852        25  .001594514   R-squared       =    0.5678
-------------+----------------------------------   Adj R-squared   =    0.5505
       Total |  .092232463        26  .003547402   Root MSE        =    .03993

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         rhs |   .1587333   .0276976     5.73   0.000     .1016889    .2157776
       _cons |   .0050653   .0081162     0.62   0.538    -.0116503    .0217809
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-03.2fc round(b[1,1],0.01)

. global se1: display %-03.2fc round(sqrt(V[1,1]),0.01)

. display "$c1"
0.16

. 
. reg `LHS1' `LHS2' `RHS'

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(2, 24)        =    200.53
       Model |  .645714201         2  .322857101   Prob > F        =    0.0000
    Residual |  .038640316        24  .001610013   R-squared       =    0.9435
-------------+----------------------------------   Adj R-squared   =    0.9388
       Total |  .684354518        26  .026321328   Root MSE        =    .04012

-------------------------------------------------------------------------------
      D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
ln_gdp_pw_ppp |   .1696791   .0305353     5.56   0.000     .1066575    .2327008
       ln_pop |    .103251   .0063709    16.21   0.000      .090102    .1163999
        _cons |   .0150362   .0140514     1.07   0.295    -.0139645    .0440368
-------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-04.2fc round(b[1,1],0.0001)

. global se1: display %-04.2fc round(sqrt(V[1,1]),0.0001)

. 
. 
. *Figure 
. *--------------------------------------------------------------------
. local ytitle "{&Delta}`=ustrunescape("\u03D5\u0305")'{sub:n}"

. local xtitle "{&Delta}y{sub:n}"

. 
. global opt1 msymbol(circle_hollow) mlabel(isocode) mlabcolor(red)  msize(small) mlabsize(small)

. global opt2 msymbol(square_hollow) mlabel(isocode) mlabcolor(blue) msize(small) mlabsize(small)

. two (scatter lhs rhs, sort $opt1  mcolor(red)) (lfit lhs rhs, lcolor(red)) (line lhs lhs, lcolor(none)) ,  ylabel(-0.4(0.2)0.2, format(%5.1f) labsize(medlarge)) xlabel(-1(0.2)0
> .4, format(%5.1f) labsize(medlarge)) ///
>         title("", size(small)) ytitle("`ytitle'", size(medlarge)) xtitle("`xtitle'", size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
>         legend(order(2 "`ytitle': $c1 ($se1)") rows(1) size(medlarge) bplace(se) ring(0) region(lwidth(none))) 

. 
. graph export "${rmain}/fig_03.pdf", replace
(file F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/results/main/fig_03.pdf written in PDF format)

. 
. 
end of do-file

. do "F:\Dropbox (UBC-Umich)\Research_Projects\Project Javier and Natalia\TFP firm\TFP_firm_data_historical\dataverse_files\code\main\figure_03_phi_pop.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: figure_03_phi_pop.do
> Date: October 2022
> 
> Description: Reproduces Figure 3: Development accounting: firm-embedded productivity residualized by population.
> 
> *****************************************************************************************/
. 
. *-------------------------------------------------------------------------------
. global typeden=1

. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main"

. global cappendix "${root}/code/appendix"

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main"

. global rappendix  "${root}/results/appendix"

. 
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. *global maindirectory "F:/Dropbox (UBC-Umich)"
. *global maindirectory "C:\Users\cheoy\Dropbox (UBC-Umich)"
. *global tfp "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical" 
. *global tfp_bef "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data" 
. *global orbis_historical "${maindirectory}/Master_Dataset/Orbis_master/Javier_Florian/orbis_data/final_data"
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. 
. *global inputs "${tfp}/data/inputs"
. *global code "${tfp}/code"
. *global output "${tfp}/data/output"
. *global results "${tfp}/results"
. 
. 
. 
. 
. 
. 
. 
. 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. global lf "LF"

. 
. *Log
. *cap log close
. *log using "${clogs}/figure_03_phi_pop.log",replace
. *-------------------------------------------------------------------------------
. 
. 
. 
. *-----------------------------------------------------------------
. clear all

. use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

. 
. local grvar0 "gdp_pw_ppp" 

. local grvar1 "" 

. local var3 "A"

. local yy "2016"

. merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable type was str5, now str9 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,985
        from master                         0  (_merge==1)
        from using                      2,985  (_merge==2)

    matched                                27  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(2,985 observations deleted)

. drop _merge

. 
. foreach var in D_A  {
  2. gen `var'_phi=(-1)*`var'*(0.2)
  3. }

. 
. local LHS1 D_`var3'_phi

. local LHS2 ln_`grvar0'

. local RHS ln_pop

. 
. 
. reg `LHS1' `LHS2' `RHS'

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(2, 24)        =    200.53
       Model |  .645714201         2  .322857101   Prob > F        =    0.0000
    Residual |  .038640316        24  .001610013   R-squared       =    0.9435
-------------+----------------------------------   Adj R-squared   =    0.9388
       Total |  .684354518        26  .026321328   Root MSE        =    .04012

-------------------------------------------------------------------------------
      D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
ln_gdp_pw_ppp |   .1696791   .0305353     5.56   0.000     .1066575    .2327008
       ln_pop |    .103251   .0063709    16.21   0.000      .090102    .1163999
        _cons |   .0150362   .0140514     1.07   0.295    -.0139645    .0440368
-------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-04.2fc round(b[1,1],0.0001)

. global se1: display %-04.2fc round(sqrt(V[1,1]),0.0001)

. 
. 
. reg `LHS1' `RHS', nocon

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =    470.38
       Model |  1.71648939         1  1.71648939   Prob > F        =    0.0000
    Residual |  .094877256        26  .003649125   R-squared       =    0.9476
-------------+----------------------------------   Adj R-squared   =    0.9456
       Total |  1.81136665        27  .067087654   Root MSE        =    .06041

------------------------------------------------------------------------------
     D_A_phi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1245806   .0057441    21.69   0.000     .1127734    .1363879
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_first: display %-03.2fc round(b[1,1],0.0001)

. global se_first: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict lhs, res

. 
. reg `LHS2' `RHS', nocon 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 26)        =     31.54
       Model |  2.81238372         1  2.81238372   Prob > F        =    0.0000
    Residual |   2.3183727        26  .089168181   R-squared       =    0.5481
-------------+----------------------------------   Adj R-squared   =    0.5308
       Total |  5.13075642        27  .190028016   Root MSE        =    .29861

------------------------------------------------------------------------------
ln_gdp_pw_~p |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      ln_pop |   .1594657   .0283945     5.62   0.000     .1010999    .2178315
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c_second: display %-03.2fc round(b[1,1],0.0001)

. global se_second: display %-03.2fc round(sqrt(V[1,1]),0.0001)

. predict rhs, res

. 
. reg lhs rhs 

      Source |       SS           df       MS      Number of obs   =        27
-------------+----------------------------------   F(1, 25)        =     32.84
       Model |  .052369611         1  .052369611   Prob > F        =    0.0000
    Residual |  .039862852        25  .001594514   R-squared       =    0.5678
-------------+----------------------------------   Adj R-squared   =    0.5505
       Total |  .092232463        26  .003547402   Root MSE        =    .03993

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         rhs |   .1587333   .0276976     5.73   0.000     .1016889    .2157776
       _cons |   .0050653   .0081162     0.62   0.538    -.0116503    .0217809
------------------------------------------------------------------------------

. mat b = e(b)

. mat V = e(V)

. global c1: display %-03.2fc round(b[1,1],0.01)

. global se1: display %-03.2fc round(sqrt(V[1,1]),0.01)

. display "$c1"
0.16

. 
. 
. *Figure 
. *--------------------------------------------------------------------
. local ytitle "{&Delta}`=ustrunescape("\u03D5\u0305")'{sub:n}"

. local xtitle "{&Delta}y{sub:n}"

. 
. global opt1 msymbol(circle_hollow) mlabel(isocode) mlabcolor(red)  msize(small) mlabsize(small)

. global opt2 msymbol(square_hollow) mlabel(isocode) mlabcolor(blue) msize(small) mlabsize(small)

. two (scatter lhs rhs, sort $opt1  mcolor(red)) (lfit lhs rhs, lcolor(red)) (line lhs lhs, lcolor(none)) ,  ylabel(-0.4(0.2)0.2, format(%5.1f) labsize(medlarge)) xlabel(-1(0.2)0
> .4, format(%5.1f) labsize(medlarge)) ///
>         title("", size(small)) ytitle("`ytitle'", size(medlarge)) xtitle("`xtitle'", size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
>         legend(order(2 "`ytitle': $c1 ($se1)") rows(1) size(medlarge) bplace(se) ring(0) region(lwidth(none))) 

. 
. graph export "${rmain}/fig_03.pdf", replace
(file F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/results/main/fig_03.pdf written in PDF format)

. 
. 
. 
. 
.         
. 
.         
.         
.         
.         
.         
. 
end of do-file

. do "F:\Dropbox (UBC-Umich)\Research_Projects\Project Javier and Natalia\TFP firm\TFP_firm_data_historical\dataverse_files\code\main\figure_03_phi_pop.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: figure_03_phi_pop.do
> Date: October 2022
> 
> Description: Reproduces Figure 3: Development accounting: firm-embedded productivity residualized by population.
> 
> *****************************************************************************************/
. 
. *-------------------------------------------------------------------------------
. global typeden=1

. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main"

. global cappendix "${root}/code/appendix"

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main"

. global rappendix  "${root}/results/appendix"

. 
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. *global maindirectory "F:/Dropbox (UBC-Umich)"
. *global maindirectory "C:\Users\cheoy\Dropbox (UBC-Umich)"
. *global tfp "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical" 
. *global tfp_bef "${maindirectory}/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data" 
. *global orbis_historical "${maindirectory}/Master_Dataset/Orbis_master/Javier_Florian/orbis_data/final_data"
. ************** ESTO DE ACA ES LO QUE TENGO QUE BORRAR **************
. 
. *global inputs "${tfp}/data/inputs"
. *global code "${tfp}/code"
. *global output "${tfp}/data/output"
. *global results "${tfp}/results"
. 
. 
. 
. 
. 
. 
. 
. 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. global lf "LF"

. 
. *Log
. cap log close
